package edu.java.texbooks.scjp.test04;

public class MyException {

    static String[] gooFoods = { "Butter", "Rice", "Fruit" };

    public static void main(String[] args) {
	try {
	    checkFood("Fruits");
	} catch (BadFoodException bfe) {
	    System.out.println("BadFoodException ");
	}

	System.out.println("Finish");
    }

    public static void checkFood(String food) throws BadFoodException {
	if (isInArray(food)) {
	    System.out.println("It's a nice food :)");
	} else {
	    throw new BadFoodException();
	}
    }

    public static boolean isInArray(String aFood) {
	for (String food : gooFoods) {
	    if (aFood == food) {
		return true;
	    }
	}
	return false;
    }

}
